﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MM.Commmon.UI.Properties;

namespace MM.Commmon.UI
{
    public partial class FrmHint : Form
    {
        public FrmHint()
        {
            InitializeComponent();
        }

        public FrmHint(string text, MessageBoxIcon icon, double visibleSeconds): this()
        {
            this.lblHint.Text = text;
            switch (icon)
            {
                case MessageBoxIcon.Exclamation:
                    this.pbIcon.BackgroundImage = Resources.dwyy;
                    break;

                case MessageBoxIcon.Asterisk:
                    this.pbIcon.BackgroundImage = Resources.dwgl;
                    break;

                case MessageBoxIcon.Hand:
                    this.pbIcon.BackgroundImage = Resources.dwjz;
                    break;

                case MessageBoxIcon.Question:
                    this.pbIcon.BackgroundImage = Resources.gryy;
                    break;

                default:
                    this.pbIcon.BackgroundImage = Resources.hddj;
                    break;
            }
            this.pbIcon.Refresh();
            int winWidth = (this.lblHint.Left + this.lblHint.Width) + 20;
            if (winWidth > ((Screen.PrimaryScreen.Bounds.Width * 2) / 3))
            {
                winWidth = (Screen.PrimaryScreen.Bounds.Width * 2) / 3;
            }
            if (winWidth > base.Width)
            {
                this.SetLocation(winWidth);
            }
            this.timerOpacity.Interval = (int)Math.Round((double)((visibleSeconds * 1000.0) / 5.0));
            this.timerOpacity.Enabled = true;
        }

        private void SetLocation(int winWidth)
        {
            base.Width = winWidth;
            base.Left = (Screen.PrimaryScreen.Bounds.Width - base.Width) - 20;
            base.Top = 20;
        }

        private void timerOpacity_Tick(object sender, EventArgs e)
        {
            if (base.Opacity < 0.2)
            {
                base.Opacity = 0.0;
                this.lblHint.Text = "";
                this.timerOpacity.Enabled = false;
                base.Close();
            }
            else
            {
                base.Opacity -= 0.2;
            }
        }
    }
}
